package com.digitalchina.lxnsy.viewholder;

import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.entity.ExpertVO;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.facebook.drawee.view.SimpleDraweeView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;


/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：白彦东
 * 创建时间：2016/12/28 18:10
 * 修改备注：
 * ================================================
 */

public class HotExpertListHolder extends BaseViewHolder<ExpertVO> {

    private SimpleDraweeView ivImage;
    private TextView tvExpertName;
    private TextView tvExpertTitle;
    private TextView tvExpertProvince;
    private TextView tvExpertUniverse;
    private ImageView ivExpertContact;


    public HotExpertListHolder(ViewGroup parent) {
        super(parent, R.layout.item_hot_experts);
        ivImage = $(R.id.item_iv_hot_expert_avatar);
        ivExpertContact = $(R.id.item_iv_hot_expert_contact);
        tvExpertName = $(R.id.item_tv_hot_expert_name);
        tvExpertTitle = $(R.id.item_tv_hot_expert_titles);
        tvExpertProvince = $(R.id.item_tv_hot_expert_province);
        tvExpertUniverse = $(R.id.item_tv_hot_expert_universe_name);
    }

    @Override
    public void setData(final ExpertVO data) {
        super.setData(data);

        FrescoUtil.showImageSmall(data.getPhoto() != null ? data.getPhoto() : "", ivImage);
        tvExpertName.setText(data.getExpertName() != null ? data.getExpertName() : "");
        if (!TextUtils.isEmpty(data.getExpertSex())) {
            if (data.getExpertSex().equals("男")) {
                isMale();
            } else {
                isFemale();
            }
        }
        tvExpertTitle.setText(data.getTitle() != null ? data.getTitle() : "");
        tvExpertProvince.setText(data.getAddress() != null ? data.getAddress() : "");
        tvExpertUniverse.setText(data.getWorkUnit() != null ? data.getWorkUnit() : "");

        ivExpertContact.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                }
        });
    }

    private void isMale() {
        Drawable drawable = getContext().getResources().getDrawable(R.drawable.icon_male);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tvExpertName.setCompoundDrawables(drawable, null, null, null);
    }

    private void isFemale() {
        Drawable drawable = getContext().getResources().getDrawable(R.drawable.icon_female);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tvExpertName.setCompoundDrawables(drawable, null, null, null);
    }
}
